package com.qf.controller;

import com.qf.pojo.resp.BaseResp;
import com.qf.service.ShopCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ShopCartController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/28 20:37
 * @Version 1.0
 **/
@RestController
@RequestMapping("shop")
@Api(tags = "购物车操作")
@CrossOrigin
public class ShopCartController {
    @Autowired
    ShopCartService shopCartService;


    @GetMapping("findByUser")
    @ApiOperation("通过用户获取当前用户的购物车")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value = "用户主键",required = true)})
    public BaseResp findByUser(int id){
        return  shopCartService.findByUser(id);
    }

    @GetMapping("upToCart")
    @ApiOperation("添加商品至购物车,点击加号添加商品数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户的主键"),
            @ApiImplicitParam(name = "gid",value = "商品的id")
    })
    public BaseResp upToCart(int uid,int gid){
        return shopCartService.upToCart(uid,gid);
    }

    @GetMapping("divGoods")
    @ApiOperation("购物车点击减号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户的主键"),
            @ApiImplicitParam(name = "gid",value = "商品的id")
    })
    public BaseResp divGoods(int uid,int gid){
        return shopCartService.divCart(uid,gid);
    }

    @GetMapping("cleanCart")
    @ApiOperation("清空购物车")
    @ApiImplicitParams({@ApiImplicitParam(name = "uid", value = "用户id")})
    public BaseResp cleanCart(int uid){
        return shopCartService.cleanCart(uid);
    }


}
